$(function(){
    var config = new Config();
    config.init().init();
});

function Config(){
    this.init = function(){
        return CONFIG;
    };
    
    var CONFIG = {
        init : function(){
            CONFIG.funs.initUpload();
            CONFIG.lieteners.bindEvents();
        },
        lieteners : {
            bindEvents : function(){
                $.util.foreachFunction(this, [ "bindEvents" ]);
            },
            bindFormSubmit : function(){
                $("#btn_notice_add_submit").click(function(){
                    var $form = $("#frm_config");
                    
                    $form.validate();
                    $form.submit();
                });
            },
            bindModuleChange : function(){
                $("#sel_seo_module").change(function(){
                    var module = $(this).val();
                    $.post(SYSTEM_DATA.contextPath + "/Config/findSeoConfig.shtml", {
                        'module' : module
                    }, function(jsonResult){
                        if(null == jsonResult.data){
                            $("#txa_title").val("");
                            $("#txa_keyword").val("");
                            $("#txa_description").val("");
                        }else{
                            $("#txa_title").val(jsonResult.data.title);
                            $("#txa_keyword").val(jsonResult.data.keyword);
                            $("#txa_description").val(jsonResult.data.description);
                        }
                    }, "json");
                });
            },
            bindUpload : function(){
                $("#inp_background_color_upload_enter").click(function(){
                    $('#inp_background_color_upload').uploadifyUpload();
                });
            }
        },
        funs :{
            initUpload : function(){
                $('#inp_background_color_upload').uploadify({
                    'uploader'  : SYSTEM_DATA.public_path + '/js/plugin/Uploadify/uploadify.swf',
                    'script'    : SYSTEM_DATA.contextPath + '/File/uploadBackGround.shtml',
                    'cancelImg' : SYSTEM_DATA.public_path + '/js/plugin/Uploadify/cancel.png',
                    'folder'    : '/uploads',
                    'removeCompleted' : true,
                    'auto'       : false,
                    'fileExt' : '*.jpg;',
                    'fileDesc' : '可上传的图片文件',
                    'sizeLimit' : 1024 * 1024 * 2,
                    //'height' : 18,
                    //'buttonText' : '上传',
                    'onComplete'  : function(event, ID, fileObj, response, data) {
                        //console.debug(response);
                        response = $.parseJSON(response);
                        console.debug(response);
                        
                    },
                    'onError' : function(event,ID,fileObj,errorObj) {
                        console.debug(errorObj);
                    }
                });
            }
            
            
        }
    };
}